{extend name="common:base"/}
{block name="body"}
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-12">
        <h2>系统</h2>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>菜单管理</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i> 
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="{:\\think\\Url::build('index',['pid'=>$father['pid']??0])}">返回{$father.title|default=''}</a>
                            </li>
                        </ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-9 m-b-xs">
                            <a class="btn btn-outline btn-primary" href="{:\\think\\Url::build('Menu/add',['pid'=>$pid??0])}">新增</a>
                            <a id="import" class="btn btn-outline btn-info">导入</a>
                            <button type="button" class="btn btn-outline btn-danger ajax-post confirm" url="{:\\think\\Url::build('batchUpdate',['value'=>-1])}" target-form="ids">删除</button>
                        </div>
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input type="text" placeholder="请输入关键词" class="input-sm form-control"> <span class="input-group-btn">
                                    <button type="button" class="btn btn-sm btn-primary"> 搜索</button> </span>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th class="">
                                        <input class=" checkbox check-all" type="checkbox">
                                    </th>
                                    <th>ID</th>
                                    <th>名称</th>
                                    <th>上级菜单</th>
                                    <th>分组</th>
                                    <th>URL</th>
                                    <th>排序</th>
                                    <th>仅开发者模式显示</th>
                                    <th>隐藏</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {notempty name="data"}
                                {volist name="data" id="vo"}
                                <tr>
                                    <td><input class="ids " type="checkbox" name="ids[]" value="{$vo.id}"></td>
                                    <td>{$vo.id}</td>
                                    <td>
                                        <a href="{:\\think\\Url::build('index',['pid'=>$vo['id']])}">{$vo.title}</a>
                                    </td>
                                    <td>{$father.title|default='无'}</td>
                                    <td>{$vo.group}</td>
                                    <td>{$vo.url}</td>
                                    <td><input name="sort" data_id="{$vo.id}" class="input-x text-center is_sort" value="{$vo.sort}"></td>
                                    <td>
                                        <a href="{:\\think\\Url::build('toogle',['ids'=>$vo['id'],'value'=>abs($vo['is_dev']-1),'field'=>'is_dev'])}" class="ajax-get ">
                                            {$vo.is_dev|change_status=[1 => '是', 0 => '否']}
                                        </a>
                                    </td>
                                    <td>
                                        <a href="{:\\think\\Url::build('toogle',['ids'=>$vo['id'],'value'=>abs($vo['hide']-1),'field'=>'hide'])}" class="ajax-get ">
                                            {$vo.hide|change_status=[1 => '是',0 => '否']}
                                        </a>
                                    </td>
                                    <td>
                                        <a title="编辑" href="{:\\think\\Url::build('edit',['id'=>$vo['id']])}">编辑</a>
                                        <a class="ajax-get confirm" title="编辑" href="{:\\think\\Url::build('setStatus',['value'=>abs($vo['status']-1),'ids'=>$vo['id']])}">{$vo.status|change_status=[1 => '禁用', 0 => '启用']}</a>
                                        <a class="confirm ajax-get" title="删除" href="{:\\think\\Url::build('setStatus',['value'=>-1,'ids'=>$vo['id']])}">删除</a>
                                    </td>
                                </tr>
                                {/volist}
                                {else /}
                            <td colspan="10" class="text-center"> aOh! 暂时还没有内容! </td>
                            {/notempty}
                            </tbody>
                        </table>
                    </div>
                    <div class="text-center">
                        {$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        highlight_subnav("{:\\think\\Url::build('menu/index')}");
        $(".is_sort").blur(function () {
            var val = $(this).val();
            if (isNaN(val)) {
                alert_msg('排序必须为一个数字', 0);
            }
            var id = $(this).attr('data_id');
            $.get("{:\\think\\Url::build('currentSort')}", {id: id, sort: val}, function (data) {
                if (data.code == 1) {
                    data.url ? alert_msg(data.msg + ',页面即将自动跳转~', 1) : alert_msg(data.msg, 1);
                    setTimeout(function () {
                        if (data.url) {
                            location.href = data.url;
                        } else {
                            location.reload();
                        }
                    }, 1500);
                } else {
                    alert_msg(data.msg, 0);
                    setTimeout(function () {
                        if (data.url) {
                            location.href = data.url;
                        }
                    }, 1500);
                }
            });
        });
    });
    $("#import").on('click', function () {
        var pid = "{$pid|default=0}";
        $.get("{:\\think\\Url::build('menu/import')}", {pid: pid}, function (str) {
            if (str.code === 0) {
                return alert_msg(str.msg);
            }
            layer.open({
                type: 1,
                title: "菜单导入",
                area: '550px',
                content: str
            });

        });
    });
</script>
{/block}